using System;
using System.Collections.Generic;
using System.Reflection;

namespace DapperExtensionsNew
{
    public static class TypeExtensions
    {
        public static IEnumerable<PropertyInfo> GetAllProperties<T>(this T entity) where T : class
        {
            if (entity == null)
            {
                return new PropertyInfo[0];
            }
            return entity.GetType().GetProperties();
        }

        public static bool IsSimpleType(this Type type)
        {
            type = Nullable.GetUnderlyingType(type) ?? type;
            if (!new List<Type>
            {
                typeof(byte),
                typeof(sbyte),
                typeof(short),
                typeof(ushort),
                typeof(int),
                typeof(uint),
                typeof(long),
                typeof(ulong),
                typeof(float),
                typeof(double),
                typeof(decimal),
                typeof(bool),
                typeof(string),
                typeof(char),
                typeof(Guid),
                typeof(DateTime),
                typeof(DateTimeOffset),
                typeof(byte[])
            }.Contains(type))
            {
                return type.IsEnum;
            }
            return true;
        }
    }
}
